package com.cl.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.*;
import jakarta.servlet.http.HttpServletRequest;

import com.cl.utils.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cl.annotation.IgnoreAuth;
import com.cl.annotation.SysLog;

import com.cl.entity.ProductClassificationEntity;
import com.cl.entity.view.ProductClassificationView;

import com.cl.service.ProductClassificationService;
import com.cl.service.TokenService;
import com.cl.utils.PageUtils;
import com.cl.utils.R;
import com.cl.utils.EncryptUtil;
import com.cl.utils.MPUtil;
import com.cl.utils.MapUtils;
import com.cl.utils.CommonUtil;
import java.io.IOException;

/**
 * 商品分类
 * 后端接口
 * @author 
 * @email 
 * @date 2025-03-19 16:07:07
 */
@RestController
@RequestMapping("/productclassification")
public class ProductClassificationController {
    @Autowired
    private ProductClassificationService productClassificationService;







    /**
     * 后台列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,ProductClassificationEntity productClassification,
                                            HttpServletRequest request){
                                    QueryWrapper<ProductClassificationEntity> ew = new QueryWrapper<ProductClassificationEntity>();
                                                        
        
        
        PageUtils page = productClassificationService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, productClassification), params), params));
        return R.ok().put("data", page);
    }







    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,ProductClassificationEntity productClassification,
		HttpServletRequest request){
        QueryWrapper<ProductClassificationEntity> ew = new QueryWrapper<ProductClassificationEntity>();

		PageUtils page = productClassificationService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, productClassification), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( ProductClassificationEntity productClassification){
       	QueryWrapper<ProductClassificationEntity> ew = new QueryWrapper<ProductClassificationEntity>();
      	ew.allEq(MPUtil.allEQMapPre( productClassification, "productClassification"));
        return R.ok().put("data", productClassificationService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(ProductClassificationEntity productClassification){
        QueryWrapper< ProductClassificationEntity> ew = new QueryWrapper< ProductClassificationEntity>();
 		ew.allEq(MPUtil.allEQMapPre( productClassification, "productClassification"));
		ProductClassificationView productClassificationView =  productClassificationService.selectView(ew);
		return R.ok("查询商品分类成功").put("data", productClassificationView);
    }

    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        ProductClassificationEntity productClassification = productClassificationService.getById(id);
		productClassification = productClassificationService.selectView(new QueryWrapper<ProductClassificationEntity>().eq("id", id));
        return R.ok().put("data", productClassification);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        ProductClassificationEntity productClassification = productClassificationService.getById(id);
		productClassification = productClassificationService.selectView(new QueryWrapper<ProductClassificationEntity>().eq("id", id));
        return R.ok().put("data", productClassification);
    }




    /**
     * 后端保存
     */
    @RequestMapping("/save")
    @SysLog("新增商品分类")
    public R save(@RequestBody ProductClassificationEntity productClassification, HttpServletRequest request){
        //ValidatorUtils.validateEntity(productClassification);
        productClassificationService.save(productClassification);
        return R.ok().put("data",productClassification.getId());
    }

    /**
     * 前端保存
     */
    @SysLog("新增商品分类")
    @RequestMapping("/add")
    public R add(@RequestBody ProductClassificationEntity productClassification, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(productClassification);
        productClassificationService.save(productClassification);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    @SysLog("修改商品分类")
    public R update(@RequestBody ProductClassificationEntity productClassification, HttpServletRequest request){
        //ValidatorUtils.validateEntity(productClassification);
        productClassificationService.updateById(productClassification);//全部更新
        return R.ok();
    }





    /**
     * 删除
     */
    @RequestMapping("/delete")
    @SysLog("删除商品分类")
    public R delete(@RequestBody Long[] ids){
        productClassificationService.removeBatchByIds(Arrays.asList(ids));
        return R.ok();
    }











}
